Namespacing everything to /UVa.
[and.git] / UVa / 11203 - Can you decide it for ME / problem11203.dpr
blobe6aadf27e7028f4a3692009f94cad6f69adc83b4
1 program problem11203 (input, output);\r
2 \r
3 {$APPTYPE CONSOLE}\r
4 \r
5 \r
6 Function StrToInt(Const S: String): Integer;\r
7 Var\r
8   E: Integer;\r
9 Begin\r
10   Val(S, Result, E);\r
11 End;\r
14 function allCharsEqual(s : string; c : char) : boolean;\r
15 //Returns true if all chars from s equal c\r
16 var\r
17   i : integer;\r
18 begin\r
19 result := true;\r
20 for i := 1 to length(s) do\r
21   if s[i] <> c then\r
22     result := false;\r
23 end;\r
25 function extract(s : string; var x : string; var y: string; var z : string) : boolean;\r
26 //returns true if it can extract x, y and z with the correct format, false otherwise.\r
27 var\r
28   i : integer;\r
29 begin\r
30 result := true;\r
31 i := 1;\r
32 x := '';\r
33 //Extract x\r
34 while ((s[i] <> 'M') and (i <= length(s))) do\r
35   begin\r
36   x := x + s[i];\r
37   inc(i);\r
38   end;\r
40 if (x = '') or (not allCharsEqual(x, '?')) then\r
41   begin\r
42   result := false;\r
43   exit;\r
44   end;\r
47 //delete from S from the beggining until the last character of x\r
48 s := copy(s, i, length(s));\r
49 if (s[1] <> 'M') then //if next char is not an M\r
50   begin\r
51   result := false;\r
52   exit;\r
53   end;\r
55 s := copy(s, 2, length(s)); //delete the M\r
56 i := 1;\r
57 y := '';\r
58 //Extract y\r
59 while ((s[i] <> 'E') and (i <= length(s))) do\r
60   begin\r
61   y := y + s[i];\r
62   inc(i);\r
63   end;\r
65 if (y = '') or (not allCharsEqual(y, '?')) then\r
66   begin\r
67   result := false;\r
68   exit;\r
69   end;\r
71 //delete from S from the beggining until the last character of y\r
72 s := copy(s, i, length(s));\r
73 if s[1] <> 'E' then\r
74   begin\r
75   result := false;\r
76   exit;\r
77   end;\r
79 z := copy(s, 2, length(s)); //delete the E\r
80 if (z = '') or (not allCharsEqual(z, '?')) then\r
81   begin\r
82   result := false;\r
83   exit;\r
84   end;\r
85 end;\r
87 function isTheorem(s : string) : boolean;\r
88 var\r
89   x, y, z : string;\r
90   i : integer;\r
91 begin\r
92 result := false;\r
93 if extract(s, x, y, z) then\r
94   result := (x + y = z);\r
95 end;\r
98 var\r
99   howMany : integer;\r
100   i, principalLoop : integer;\r
101   line : String;\r
102   correctChars : Set of char;\r
103   invalid : boolean;\r
105 //Main:\r
106 begin\r
107 //reset(input, 'input.txt');\r
108 //reset(output, 'out.txt');\r
109 correctChars := ['M', 'E', '?'];\r
110 readLn(line);\r
111 howMany := strToInt(line);\r
113 for principalLoop := 1 to howMany do\r
114   begin\r
115   invalid := false;\r
116   readLn(line);\r
117   for i := 1 to length(line) do\r
118       if not (line[i] in correctChars) then\r
119         invalid := true;\r
120   if invalid then\r
121     writeLn('no-theorem')\r
122   else\r
123     begin\r
124     if isTheorem(line) then\r
125       writeLn('theorem')\r
126     else\r
127       writeLn('no-theorem');\r
128     end;\r
129   end;\r
130 end.\r